﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using Framework.Define;

public class MenuAppendUIComponent : EditorWindow
{
    private const int cPriority = 3000;

    [MenuItem("GameObject/UICustom/UIButton", priority = cPriority)]
    public static void AppendUIButton()
    {
        AppendUIComponent("UIButton");
    }

    [MenuItem("GameObject/UICustom/UIInputField", priority = cPriority)]
    public static void AppendUIInputField()
    {
        AppendUIComponent("UIInputField");
    }

    [MenuItem("GameObject/UICustom/UISlider", priority = cPriority)]
    public static void AppendUISlider()
    {
        AppendUIComponent("UISlider");
    }

    [MenuItem("GameObject/UICustom/UIText", priority = cPriority)]
    public static void AppendUIText()
    {
        AppendUIComponent("UIText");
    }

    [MenuItem("GameObject/UICustom/UIToggle", priority = cPriority)]
    public static void AppendUIToggle()
    {
        AppendUIComponent("UIToggle");
    }

    private static void AppendUIComponent(string pUIName)
    {
        string path = string.Format("Assets/{0}/{1}.prefab", FrameworkDefine.UIComponentRootDirectoryPath, pUIName);
        GameObject uiGameObject = Instantiate(AssetDatabase.LoadAssetAtPath<GameObject>(path));
        uiGameObject.name = pUIName;
        uiGameObject.transform.SetParent(Selection.activeTransform, false);
    }
}
